<template>
	<view>
		<liuyuno-tabs :tabData="typeList" @tabClick="typeClick" />

		<uni-list>
			<uni-list-item v-for="(item,index) in resList" :key="index" showArrow clickable
				@click="toContentPage(item.id)" :title="item.title"/>
		</uni-list>

		<uni-fab :pattern="pattern" horizontal="right" vertical="bottom"
			@fabClick="fabClick"></uni-fab>
	</view>
</template>

<script>
	import knowledge from '@/api/modules/knowledge'
	import common from '@/api/modules/common'

	export default {
		data() {
			return {
				typeList: [], //制度类型tab
				ruleList: [], //所有制度内容
				resList : [], //制度类型对应内容
				selectedType : '', //选中制度类型
				pattern: {
					buttonColor: '#007AFF',
					icon: 'chat',
				},
			}
		},
		created() {
			common.getDictByType("rule_type").then(res=> {
				this.typeList = [
				  ...res.data.map(item => {
				    let obj = {};
					obj.id = item.dictValue;
					obj.name = item.dictLabel;
				    return obj;
				  })
				];
				this.selectedType = this.typeList[0].id;

				knowledge.getRuleList().then(res=> {
					this.ruleList = res.data;
					this.updateResList();
				})
			})
		},
		methods: {
			updateResList() {
				this.resList = this.ruleList.filter(rule => String(rule.type) === this.selectedType);
			},
			typeClick(index) {
				this.selectedType = this.typeList[index].id ;
				this.updateResList();
			},
			toContentPage(id) {
				uni.navigateTo({
					url: `/pages_duty/common/knowledge/ruleRegulation/ruleRegulationDetails?id=${id}`
				})
			},
			fabClick() {
				uni.navigateTo({
					url: '/pages_duty/common/ai/aiChat'
				})
			}
		}
	}
</script>

<style>
</style>
